home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
castools.zip
/
FAXERROR.C
< prev
next >
Wrap
Text File
|
1990-01-11
|
4KB
|
115 lines
/*
FAXERROR.C The error handler for applications using the CAS Toolkit.
This function finds information about warning or error conditions
generated by calls to the CAS Toolkit functions.
INPUT: Optional: A message from the calling application, and a pointer
to a string of warning or error information.
Global: The external Toolkit variables FAXerrno and CASerrorcode,
and the external C Library variable errno.
OUTPUT: A string of information about the warning or error, and an
error class number (constants defined in CAS.H).
The following table shows the error conditions checked for:
HLT = High Level Toolkit
LLT = Low level Toolkit (CAS calls)
HLT LLT Kind of error
-----------------------------------------------------
0 0 NO ERROR
0 1 CAS error from LLT function or logged event.
1 0 High-level Toolkit function only.
1 1 HLT function calling a LLT function.
*/
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <cas.h>
#include <fax.h>
char * pascal FAXError(char *MessageIn,
char *MessageOut,
int *ErrorClass)
{
char *temp,
tempstr[MSGLENGTH];
int i;
unsigned sizeofmsg = 0;
if (MessageOut) { /* It had better be big enough */
temp = MessageOut;
}
else {
temp = (char *)malloc(3*(MSGLENGTH + 1)); /* @ message plus a '\n'newline */
}
if (MessageIn) { /* if caller supplied a msg, */
strncpy(temp, MessageIn, MSGLENGTH); /* start with that */
if (temp[MSGLENGTH-1]) {
temp[MSGLENGTH-1] = '\0';
}
strcat(temp, "\n");
}
else {
temp[0] = '\0';
}
if (FAXerrno) { /* If Toolkit caught an error */
if ((FAXerrno < 0) || (FAXerrno > LASTMESSAGE)) {
FAXerrno = LASTMESSAGE;
}
strncat(temp, FAXerrlist[FAXerrno], MSGLENGTH);
strcat(temp, "\n");
}
if (CASerrorcode) { /* There was a CAS error */
if (((unsigned)(-CASerrorcode & 0xFF00) >> 8) == MULTIPLEX) {
strncat(temp, "CCAM not installed\n", MSGLENGTH);
*ErrorClass = FATALERROR;
return(temp);
}
else {
for(i=0; i<CASnerrors; i++) {
if (CASerrors[i].errorcode == CASerrorcode) {
strncat(temp, CASerrors[i].msg, MSGLENGTH);
strcat(temp, "\n");
*ErrorClass = CASerrors[i].errorclass;
return(temp);
}
}
if (i == CASnerrors) { /* We fell through the whole list */
switch (CASerrorcode & 0xff00) {
case 0x0100: sprintf(tempstr, "DOS warning %XH\n", CASerrorcode & 0xff);
strncat(temp, tempstr, MSGLENGTH);
*ErrorClass = DOSWARNING;
break;
case 0x0300: sprintf(tempstr, "DOS fatal error %XH\n", CASerrorcode & 0xff);
strncat(temp, tempstr, MSGLENGTH);
*ErrorClass = FATALDOSERROR;
break;
default: sprintf(tempstr, "%XH not a valid CAS error code\n", CASerrorcode);
strncat(temp, tempstr, MSGLENGTH);
*ErrorClass = UNKNOWNCASERROR;
}
return(temp);
}
}
}
/* If we fell through the above, there was no CAS error */
if (FAXerrno) {
*ErrorClass = TOOLKITERROR;
}
else {
*ErrorClass = NOERROR;
}
return(temp);
}